package com.example.demo.service.impl;

import com.example.demo.dao.IHappyLockDao;
import com.example.demo.model.HappyLock;
import com.example.demo.service.IHappyLockService;
import com.example.demo.service.abs.AbstractQueryService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;


/**
 * @author chxbca
 */
@Service
@RequiredArgsConstructor
public class HappyLockServiceImpl extends AbstractQueryService implements IHappyLockService {

    private final IHappyLockDao happyLockDao;

    @Override
    public Page<HappyLock> query(String q, Pageable pageable) {
        Specification<HappyLock> specification = createSpecification(q, HappyLock.class);
        return happyLockDao.findAll(specification, pageable);
    }

    @Override
    public HappyLock findById(Integer id) {
        return happyLockDao.findById(id).
                orElseThrow(() -> new RuntimeException("id不存在"));
    }

}
